<?php

namespace app\admin\middleware;

class CrossDomain
{
    public function handle($request, \Closure $next)
    {
        header("Access-Control-Allow-Origin:*");
        header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE'); // 允许请求的类型
        header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin,Access-Token'); // 设置允许自定义请求头的字段

        if (strtoupper($request->method()) == "OPTIONS") {
            return json();
        }
        return $next($request);
    }


}